FreescaleHRP
 
Component FreescaleHRP
High Resolution PWM
Component Level: Low
Typical Usage:
(Examples of a typical usage of the component in user code. For more information please see the page Component Code Typical Usage.)

Let's assume the component name is HRP1, the BUSCLKX2 clock is 16MHz and the HRP module works in variable duty mode.

The simplest and most lightweight way of handling the High Resolution PWM Module is to use the low level methods of the component SetPeriod and SetDuty. The value passed to these methods is directly written to the appropriate register.

  MAIN.C
void main(void)
{
  ....
  HRP1_Disable();
  HRP1_SetPeriod(0x1400);    //Set frequency 100kHz
  HRP1_SetDuty(0xF00);       //Set 25% duty cycle
  HRP1_Enable();
  ....
}

The user can also use the advanced methods of the component. It is possible to select period from a predefined list using method SetPeriodMode or set value of frequency and duty using methods SetFrequencyHz and SetRatio16

  MAIN.C
void main(void)
{
  ....
  HRP1_Disable();
  HRP1_SetPeriodMode(2);    //Set frequency to the third value in the list
  HRP1_SetRatio16(0x4000);  //Set 25% duty cycle
  HRP1_Enable();
  ....
  ....
  HRP1_SetFrequencyHz(60000);
  HRP1_SetRatio16(0xC000);  //Set 75% duty cycle
  ....
}